package com.amir.common.utils

import android.annotation.SuppressLint
import android.content.Context
import android.view.Gravity
import android.widget.Toast
import androidx.annotation.StringRes

class ToastUtil {
    companion object {
        @SuppressLint("StaticFieldLeak")
        var context: Context? = null
        var toast: Toast? = null
        fun init(context: Context) {
            Companion.context = context
        }

        fun show(content: String) {
            toast?.cancel()
            toast = Toast.makeText(context, content, Toast.LENGTH_SHORT)
            toast?.setGravity(
                Gravity.CENTER,
                0,
                0
            )

            toast?.show()
        }

        fun show(@StringRes content: Int) {
            toast?.cancel()
            toast = Toast . makeText (context, content, Toast.LENGTH_SHORT)
            toast?.setGravity(
                Gravity.CENTER,
                0,
                0
            )
            toast?.show()
        }


    }
}
